<template>
    <div class="detail-wraper">
        <shopDetail :key="this.$route.query.id"  :data="{id: this.$route.query.id, name: this.$route.query.name}" />
    </div>
</template>

<script>
    import Vue from 'vue'
    import { Tabs,TabPane } from 'element-ui'
    import {mapGetters, mapActions, mapMutations} from 'vuex';
    import * as types from '../../store/mutation-types/customer/index';
    import ShopDetail from '~components/shopDetail.vue';
    import { setToken  } from '~/utils/auth'

    Vue.use(Tabs);
    Vue.use(TabPane);


    export default {
        components: {
            ShopDetail
        },
        head(){
            return {
                title: "店铺详情",
                meta: [
                    { hid: 'customer-index', name: 'customer-index', content: 'customer-index' }
                ]
            }
        },
        data () {
            return {
                detailTabsValue: null
            }
        },
        methods: {
            removeTab(targetName){
                let tabs = this.customerDetailList;
                let activeName = this.detailTabsValue;
                if (activeName === targetName) {
                    tabs.forEach((tab, index) => {
                        if ((tab.id+'') === targetName) {
                            let nextTab = tabs[index + 1] || tabs[index - 1];
                            if (nextTab) {
                                activeName = nextTab.id+'';
                            }
                        }
                    });
                }

                this.detailTabsValue = activeName;
                this.$store.commit(types.CHANGECUSTOMERDETAIL,{data:tabs.filter(tab => (tab.id+'') !== targetName)})
            }
        },
        computed: {
            ...mapGetters({
                customerDetailList: 'getCustomerDetailList'
            })
        },
        asyncData ({ store, query }) {
            /*if(!store.state.customers.customerDetailList.length){
             store.commit('CHANGECUSTOMERDETAIL',{data:[{id: query.id,customerContactId: query.customerContactId,name: query.customerName}]});
             }
             if(query.from == 'index') {
             return { detailTabsValue: store.state.customers.customerDetailList[store.state.customers.customerDetailList.length-1].id + '' }
             }*/
        },
        created() {
            setToken('parentUrl','b2cAdmin');

        }
    }
</script>

<style lang="scss">
    .detail-wraper{
        padding-top: 0px;
    }
</style>